package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IcPartyOrganizations;
import com.ruoyi.system.service.IIcPartyOrganizationsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 党团组织Controller
 * 
 * @author ruoyi
 * @date 2024-07-10
 */
@Controller
@RequestMapping("/system/icPartyOrganizations")
public class IcPartyOrganizationsController extends BaseController
{
    private String prefix = "system/icPartyOrganizations";

    @Autowired
    private IIcPartyOrganizationsService icPartyOrganizationsService;

    @RequiresPermissions("system:icPartyOrganizations:view")
    @GetMapping()
    public String icPartyOrganizations()
    {
        return prefix + "/icPartyOrganizations";
    }

    /**
     * 查询党团组织列表
     */
    @RequiresPermissions("system:icPartyOrganizations:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IcPartyOrganizations icPartyOrganizations)
    {
        startPage();
        List<IcPartyOrganizations> list = icPartyOrganizationsService.selectIcPartyOrganizationsList(icPartyOrganizations);
        return getDataTable(list);
    }

    /**
     * 导出党团组织列表
     */
    @RequiresPermissions("system:icPartyOrganizations:export")
    @Log(title = "党团组织", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IcPartyOrganizations icPartyOrganizations)
    {
        List<IcPartyOrganizations> list = icPartyOrganizationsService.selectIcPartyOrganizationsList(icPartyOrganizations);
        ExcelUtil<IcPartyOrganizations> util = new ExcelUtil<IcPartyOrganizations>(IcPartyOrganizations.class);
        return util.exportExcel(list, "党团组织数据");
    }

    /**
     * 新增党团组织
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存党团组织
     */
    @RequiresPermissions("system:icPartyOrganizations:add")
    @Log(title = "党团组织", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IcPartyOrganizations icPartyOrganizations)
    {
        return toAjax(icPartyOrganizationsService.insertIcPartyOrganizations(icPartyOrganizations));
    }

    /**
     * 修改党团组织
     */
    @RequiresPermissions("system:icPartyOrganizations:edit")
    @GetMapping("/edit/{orgId}")
    public String edit(@PathVariable("orgId") Long orgId, ModelMap mmap)
    {
        IcPartyOrganizations icPartyOrganizations = icPartyOrganizationsService.selectIcPartyOrganizationsByOrgId(orgId);
        mmap.put("icPartyOrganizations", icPartyOrganizations);
        return prefix + "/edit";
    }

    /**
     * 修改保存党团组织
     */
    @RequiresPermissions("system:icPartyOrganizations:edit")
    @Log(title = "党团组织", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IcPartyOrganizations icPartyOrganizations)
    {
        return toAjax(icPartyOrganizationsService.updateIcPartyOrganizations(icPartyOrganizations));
    }

    /**
     * 删除党团组织
     */
    @RequiresPermissions("system:icPartyOrganizations:remove")
    @Log(title = "党团组织", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(icPartyOrganizationsService.deleteIcPartyOrganizationsByOrgIds(ids));
    }
}
